<?php
/**
 * +----------------------------------------------------------------------
 * | 公共广告位模型
 * +----------------------------------------------------------------------
 */
namespace app\common\model;

use think\Model;

class Files extends Model
{
    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';




    // 一对一获取所属广告位
    public function archivesFiles()
    {
        return $this->belongsTo(ArchivesFiles::class);
    }

	//文件大小转MB
	public function getSizeAttr($value,$data)
    {
        $size = formatBytes($data['size']);
        return $size;
    }

	//文件初次用途
    public function getPurposeTextAttr($value,$data)
    {
		$purpose = ['system'=>'系统','adv'=>'广告','links'=>'链接','avatar'=>'头像','archives'=>'文档','page'=>'单页','fragment'=>'碎片','editor'=>'内容'];	

		if(!empty($data['purpose']) && array_key_exists($data['purpose'],$purpose)){
			$res = $purpose[$data['purpose']];	
		}else{
			$res = '未知';
		}
		return $res;
    }

}